package Package.Test3;

import java.util.Comparator;
import java.util.TreeSet;

public class Test3  {
    public static final void Test3(){
        TreeSet<Student> ts=new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int num=o1.getAge()-o2.getAge();
                int num2=num==0?o1.getName().compareTo(o2.getName()):num;
                return num2;
            }

        });
        //创建学生对象
        Student s1 = new Student("xishi", 29,50);
        Student s2 = new Student("wangzhaojun", 28,80);
        Student s3 = new Student("diaochan", 30,96);
        Student s4 = new Student("yangyuhuan", 33,85);
        Student s5 = new Student("linqingxia",33,128);
        Student s6 = new Student("linqingxia",33,1000);
//把学生添加到集合
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        ts.add(s6);
//遍历集合
        for (Student s : ts) {
            System.out.println(s.getName() + "," + s.getAge());
        }
    }
}
